package zdream.control.foe.mm;

import java.util.Objects;

import zdream.control.world.Box;

/**
 * <p>洛克的飞狗, 洛克专属宠物, 属于道具类.
 * </p>
 * 
 * @author Zdream
 * @since 0.0.1
 * @date 2021-08-07 (created)
 * @date 2022-06-03 (last modified)
 */
public class RushJetProp implements IMegaManProp {
	final MegaMan owner;
	RushJet rushJet;

	public RushJetProp(MegaMan owner) {
		this.owner = Objects.requireNonNull(owner);
	}

	@Override
	public void doUse() {
		if (rushJet != null && owner.world.findFoe(rushJet.id) != null) {
			takeBack();
			return;
		}

		Box mmBox = owner;

		rushJet = new RushJet(this);
		float x = (mmBox.orientation) ? mmBox.anchorX + 1.25f : mmBox.anchorX - 1.25f;
		float y = mmBox.anchorY + 0.5f;

		// TODO 动画先不整了

		owner.world.createFoe(rushJet, x, y, mmBox.orientation);
	}

	/**
	 * 收回飞狗
	 */
	private void takeBack() {
		System.out.println(this.getClass().getSimpleName() + ": 飞狗已经在场上了, 收回去");
		rushJet.destroy(); // TODO 回收的动画
		rushJet = null;
	}
}
